package com.zhongjian.technologycal.mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.base.BaseContacts;
import com.zhongjian.technologycal.mall.bean.PayAccountBean;

import java.util.List;

/**
 * Created by wei on 2018/1/29.
 * 添加银行卡信息适配器
 */

public class WithdrawAccountIdCardAdapter extends BaseAdapter {

    private Context context;
    private List<PayAccountBean> listItems;
    private LayoutInflater listContainer;

    public WithdrawAccountIdCardAdapter(Context context, List<PayAccountBean> listItems) {
        this.context = context;
        listContainer = LayoutInflater.from(context);
        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        WithdrawAccountIdCardAdapter.ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new WithdrawAccountIdCardAdapter.ViewHolder();
            convertView = listContainer.inflate(R.layout.items_pay_account_card,
                    null);
            viewHolder.card_add_withdraw_iv_head = convertView
                    .findViewById(R.id.card_add_withdraw_iv_head);
            viewHolder.card_add_withdraw_tv_name = convertView
                    .findViewById(R.id.card_add_withdraw_tv_name);
            viewHolder.card_add_withdraw_tv_account_num = convertView
                    .findViewById(R.id.card_add_withdraw_tv_account_num);
            viewHolder.card_add_withdraw_tv_account_detail = convertView
                    .findViewById(R.id.card_add_withdraw_tv_account_detail);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (WithdrawAccountIdCardAdapter.ViewHolder) convertView.getTag();
        }

        viewHolder.card_add_withdraw_tv_name.setText(listItems.get(position).getData().getBankAccount().get(position).getBankname() + "  (" +
                listItems.get(position).getData().getBankAccount().get(position).getName() + ")");
        viewHolder.card_add_withdraw_tv_account_num.setText(listItems.get(position).getData().getBankAccount().get(position).getAccount());

        Picasso.get().load(BaseContacts.BASE_URL + listItems.get(position).getData().getBankAccount().get(position).getBanklogo())
                .into(viewHolder.card_add_withdraw_iv_head);

        viewHolder.card_add_withdraw_tv_account_detail.setText(listItems.get(position).getData().getBankAccount().get(position).getBankinfo());
        return convertView;
    }

    public final class ViewHolder {
        private ImageView card_add_withdraw_iv_head;
        private TextView card_add_withdraw_tv_name;
        private TextView card_add_withdraw_tv_account_num;
        private TextView card_add_withdraw_tv_account_detail;
    }


}
